package io.jee.runshan.service.remote.weixin.impl;

import io.jee.medusa.remote.RemoteConnector;
import io.jee.runshan.domain.remote.weixin.WeixinMenuButton;
import io.jee.runshan.domain.remote.weixin.WeixinResponse;
import io.jee.runshan.service.remote.weixin.ISystemService;
import io.jee.runshan.utils.JsonUtil;
import io.jee.runshan.utils.WeixinConstant;

import java.util.List;

import org.springframework.stereotype.Component;

@Component
public class SystemServiceImpl implements ISystemService {
	private static final String createMenuButtonAction = "menu/create";
	private static final String getCallbackipAction = "getcallbackip";

	@Override
	public WeixinResponse createMenu(List<WeixinMenuButton> button) {
		String json = JsonUtil.beanToJson(button);
		json = "{\"button\":" + json + "}";
		String actionUrl = WeixinConstant.sendUrl(createMenuButtonAction);
		return RemoteConnector.post(actionUrl, json, WeixinResponse.class);
	}
	
	@Override
	public WeixinResponse getCallbackIP() {
		String actionUrl = WeixinConstant.sendUrl(getCallbackipAction);
		return RemoteConnector.post(actionUrl, null, WeixinResponse.class);
	}

}
